<template>
  <div class="school">
    <h2>学生名称：{{ name }}</h2>
    <h2 class="qwe">学生年龄：{{ myage }}</h2>
    <button @click="sendStudentName">把学生名称给school组件</button>
  </div>
</template>

<script>
import pubsub from "pubsub-js";

export default {
  name: "Student",
  data() {
    return {
      name: "抱抱",
      myage: 19,
    };
  },
  mounted() {
    // console.log("sd"+this.$on)
    // this.$bus.$emit('hello', this.name);
  },
  methods: {
    sendStudentName() {
      // pubsub.publish 发布消息
      // this.$bus.$emit('hello', this.name);
      pubsub.publish("hello", "学生名称:"+this.name)
    }
  }

};
</script>

<style lang="less" scoped>
.school {
  background-color: rgba(232, 147, 160, 0.5);
  margin: 10px 0;

  .qwe {
    font-size: 40px;
  }
}
</style>
